<?php
// +----------------------------------------------------------------------
// | HisiPHP框架[基于ThinkPHP5开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2016-2018 http://www.hisiphp.com
// +----------------------------------------------------------------------
// | HisiPHP提供个人非商业用途免费使用，商业需授权。
// +----------------------------------------------------------------------
// | Author: 橘子俊 <364666827@qq.com>，开发者QQ群：50304283
// +----------------------------------------------------------------------
namespace app\shouyin\model;

use think\Model;
use think\Loader;
use app\user\model\User as UserModel;
use app\shop\model\Shop as ShopModel;
use app\finance\model\Account as AccountModel;
use app\system\model\systemUser as systemUserModel;
use app\shouyin\model\UserBalanceLog as UserBalanceLogModel;
class UserBalance extends Model
{

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    // 自动写入时间戳
    protected $autoWriteTimestamp = true;


    public function getAccountIdTextAttr($value,$data)
    {
        return AccountModel::where('id',$data['account_id'])->value('name');
    }
    public function getAdviserIdTextAttr($value,$data)
    {
        return $this->admins($data['adviser_id']);
    }
    public function getTechnicianIdTextAttr($value,$data)
    {
        return $this->admins($data['technician_id']);
    }
    public function getTechnicianTextAttr($value,$data)
    {
        $name = systemUserModel::where('id','in', $value)->column('nick');
        return implode(',', $name);
    }
    public function getCashierIdTextAttr($value,$data)
    {
        return $this->admins($data['cashier_id']);
    }
    public function getFinanceIdTextAttr($value,$data)
    {
        return $this->admins($data['finance_id']);
    }
    public function getUserIdTextAttr($value,$data)
    {
        $user = UserModel::get($data['user_id']);
        return $user['nick'];
    }

    public function admins($id)
    {
        $admins = systemUserModel::where('id', $id)->value('nick');
        return $admins;
    }

    public function getShopIdTextAttr($value,$data)
    {
        $shop = ShopModel::get($data['shop_id']);
        // halt($shop);
        return $shop['name'];
    }
}
